//
//  HistoryUserDefault.m
//  LOSohuTV
//
//  Created by 何欣 on 15/6/14.
//  Copyright (c) 2015年 何欣. All rights reserved.
//

#import "HistoryUserDefault.h"

@implementation HistoryUserDefault

+(void)addMovieBaseInfoInUseDefault:(MovieBaseInfo *)movieModel{
    
    NSLog(@"movie ===== %@", movieModel.img);
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSArray *array = [user arrayForKey:@"allMovie" ];
    
    NSMutableArray *dataSource = [NSMutableArray arrayWithArray:array];
    
//    [dataSource removeAllObjects];
    if (dataSource.count == 0) {
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        [dic setValue:movieModel.title forKey:@"title"];
        [dic setValue:movieModel.img forKey:@"image"];
        [dic setValue:movieModel.ID forKey:@"ID"];
        
        [dataSource addObject:dic];
    }
   
    NSInteger i = 0;

    for (NSMutableDictionary *movieDic in dataSource) {
        if ([movieModel.title isEqualToString:[movieDic objectForKey:@"title"] ]) {
            i++;
        }
    }
    
    if (i == 0) {
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        [dic setValue:movieModel.title forKey:@"title"];
        [dic setValue:movieModel.img forKey:@"image"];
        [dic setValue:movieModel.ID forKey:@"ID"];
        
        [dataSource addObject:dic];
    }

    
    [user setObject:[NSArray arrayWithArray:dataSource] forKey:@"allMovie"];
    
    array = [user arrayForKey:@"allMovie"];
    
    
}

+(NSArray *)getHistoryArrayData{
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSArray *array = [user arrayForKey:@"allMovie" ];
    return array;
}

@end
